﻿<sap:ActivityDesigner Name="ctrCRM4GetPicklistValue" x:Class="TransactionServer.ActivityDesign.CRM4Activities.CRM4GetPicklistValue"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
    xmlns:ts="clr-namespace:TransactionServer.ActivityDesign.Components"
    xmlns:help="clr-namespace:TransactionServer.ActivityDesign.Helpers"
    xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="101" d:DesignWidth="246">

    <sap:ActivityDesigner.Resources>

        <ResourceDictionary x:Key="Resource">

            <help:ComboBoxItemMultipleStringConverter x:Key="comboBoxItemMultipleStringConverter"/>
            <help:ComboBoxItemStringConverter x:Key="comboBoxItemStringConverter"/>
            <help:ComboBoxItemEntityConverter x:Key="comboBoxItemEntityConverter"/>
            <help:ComboBoxItemStringVariableConverter x:Key="comboBoxItemStringVariableConverter"/>
            <help:ComboBoxItemBoolConverter x:Key="comboBoxItemBoolConverter"/>
            <help:ExpressionStringConverter x:Key="expressionStringConverter"/>

            <Style x:Key="ExpandOrCollapsedStyle" TargetType="{x:Type ContentPresenter}">
                <Setter Property="ContentTemplate" Value="{DynamicResource Collapsed}"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=ShowExpanded}" Value="true">
                        <Setter Property="ContentTemplate" Value="{DynamicResource Expanded}"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <DataTemplate x:Key="Collapsed">
                <StackPanel>
                    <TextBlock>Разверните, чтобы увидеть параметры</TextBlock>
                </StackPanel>
            </DataTemplate>

            <DataTemplate x:Key="Expanded">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="150" />
                    </Grid.ColumnDefinitions>

                    <Label Grid.Row="0" Grid.Column="0" Content="Соединение:"/>
                    <Label Grid.Row="1" Grid.Column="0" Content="Справочник:"/>
                    <Label Grid.Row="2" Grid.Column="0" Content="Атрибут:"/>
                    <Label Grid.Row="3" Grid.Column="0" Content="Значение:"/>
                    <Label Grid.Row="4" Grid.Column="0" Content="Создать новый:"/>
                    <Label Grid.Row="5" Grid.Column="0" Content="Результат:"/>

                    <ts:ConnectionControl  Grid.Row="0" Grid.Column="1" x:Name="ctrConnection" >
                        <ts:ConnectionControl.SelectedValue>
                            <MultiBinding Converter="{StaticResource comboBoxItemMultipleStringConverter}">
                                <Binding Path="Parent.ModelItem.Connection" Mode="TwoWay" />
                            </MultiBinding>
                        </ts:ConnectionControl.SelectedValue>
                    </ts:ConnectionControl>

                    <ts:EntityControl  Grid.Row="1" Grid.Column="1" x:Name="crtEntity" 
                           SelectedValue="{Binding Path=Parent.ModelItem.EntityName, Mode=TwoWay, Converter={StaticResource comboBoxItemStringConverter}}"
                           Connection="{Binding ElementName=ctrConnection, Path=SelectedValue, Mode=OneWay}">
                    </ts:EntityControl>

                    <TextBox Grid.Row="2" Grid.Column="1" 
                             Text="{Binding Path=Parent.ModelItem.AttributeName, Mode=TwoWay, Converter={StaticResource expressionStringConverter}, UpdateSourceTrigger=PropertyChanged}">
                    </TextBox>

                    <TextBox Grid.Row="3" Grid.Column="1" 
                             Text="{Binding Path=Parent.ModelItem.ValueName, Mode=TwoWay, Converter={StaticResource expressionStringConverter}, UpdateSourceTrigger=PropertyChanged}">
                    </TextBox>

                    <ts:BooleanControl Grid.Row="4" Grid.Column="1"
                              SelectedValue="{Binding Path=Parent.ModelItem.CreateNew, Mode=TwoWay, Converter={StaticResource comboBoxItemBoolConverter}}"
                              Model="{Binding ElementName=ctrCRM4GetPicklistValue, Path=ModelItem, Mode=OneWay}" >
                    </ts:BooleanControl>

                    <ts:DynamicStringVariableControl Grid.Row="5" Grid.Column="1"
                            Model="{Binding ElementName=ctrCRM4GetPicklistValue, Path=ModelItem, Mode=OneWay}" 
                            SelectedValue="{Binding Path=Parent.ModelItem.IntValue, Mode=TwoWay, Converter={StaticResource comboBoxItemStringVariableConverter}}">
                    </ts:DynamicStringVariableControl>
                </Grid>
            </DataTemplate>

        </ResourceDictionary>

    </sap:ActivityDesigner.Resources>
    <Grid>
        <ContentPresenter Style="{DynamicResource ExpandOrCollapsedStyle}" Content="{Binding}" x:Name="cntPresenter">
        </ContentPresenter>
    </Grid>
</sap:ActivityDesigner>
